<?php
	require './config/config.php';
	$ConfigSql="select * from config where id='1'";
	$ConfigInfo=mysqli_query($con,$ConfigSql);
	$ConnfigRs=mysqli_fetch_array($ConfigInfo);
	session_start();
	if(empty($_SESSION['member'])){
	    echo "<script>location='../index.php';</script>";
	    exit;
	}
	if($_GET['id']==""){
	    echo "<script>location='./add.php';</script>";
	}else{
	    $rs=mysqli_fetch_array(mysqli_query($con,"select * from type where id='".$_GET['id']."'"));
	    if($rs['id']==""){
	        echo "<script>location='./add.php';</script>";
	    }
	}
	if($_GET['ops']=="logout"){
	    $_SESSION['member']="";
	    session_destroy();
	    echo "<script>alert('您已退出登录！');location='./index.php';</script>";
	}
	if($_POST){
		$title=$_POST['title'];
		$content=$_POST['content'];
		//echo "<script>alert('".$title."---".$content."---".$open."');</script>";
		if($title=="" or $content=="" ){
			echo "<script>alert('请填写完整信息！');location='./add.php';</script>";
		}else{
		    if($open=="0" && $pwd==""){
		           echo "<script>alert('当前模式需要您填写工单密码！');location='./add.php';</script>";
		           exit;
		    }
		    if($open!="0"){
		        $pwd="";
		    }
		    $number=date('Ymd').'-'.getRandomString(4);
			$sql="INSERT INTO `feedback` (`id`, `number`, `title`, `content`, `type`, `adduser`, `addtime`, `open`, `password`) VALUES ('', '".$number."', '".$title."', '".$content."', '".$_GET['id']."', '".$_SESSION['member']."', '".date("Y/m/d H:i:s")."', '".$open."', '".$pwd."')";
			mysqli_query($con,$sql);
			$ip=getip();
		    mysqli_query($con,"INSERT INTO `log` (`id`, `user`, `ops`, `ip`, `time`) VALUES (NULL, '".$_SESSION['member']."', '发起工单 ".$title."', '".$ip."', '".date("Y/m/d H:i:s")."')");
			echo "<script>alert('成功发起工单！');location='./index.php';</script>";
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title><?php echo $ConnfigRs['name'];?>-发表问题</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="css/head.css"/>
  <link rel="stylesheet" href="layui/css/layui.css">

<link rel="stylesheet" href="css/global.css">

<script src="layui/layui.js"></script>
</head>
<body >

<div class="dvhead">
	<div class="dvlogo"><a href="index.php">你问我答</a></div>
	<div class="dvreg">
		<?php
		    if(empty($_SESSION['member'])){
                echo "已有账号，立即&nbsp;<a href='login.php'>登录</a>";
            }else{
                echo "欢迎您，".$_SESSION['member']." &nbsp;&nbsp;<a href='?ops=logout'> 退出</a>";
            }
		?>
	</div>
</div>

<div class="main layui-clear">
  <div class="fly-panel" pad20>
    <div class="layui-form layui-form-pane">
    <a href="./add.php">返回</a>
      <form method="post" action="./add2.php?id=<?php echo $_GET['id'];?>">
        <div class="layui-form-item">
          <label for="L_title" class="layui-form-label">分类</label>
          <div class="layui-input-block">
              <input type="text" value="<?php echo $rs['name'];?>" placeholder="<?php echo $rs['name'];?>" autocomplete="off" class="layui-input" disabled="disabled">
          </div>
        </div>
        <div class="layui-form-item">
          <label for="L_title" class="layui-form-label">标题</label>
          <div class="layui-input-block">
            <input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <div class="layui-input-block">
             <div class="editor">
    			<textarea id="content" name="content" style="width:1040px;height:450px;visibility:hidden;"></textarea>
  			 </div>
          </div>
          <label for="L_content" class="layui-form-label" style="top: -2px;">描述</label>
        </div>
        </div>
        <div class="layui-form-item">
          <input type="submit" name="submit" value="立即发布" class="layui-btn" lay-filter="*" lay-submit>
        </div>
      </form>
    </div>
  </div>
</div>

 <script type="text/javascript" charset="utf-8" src="js/kindeditor.js"></script>
  <script type="text/javascript">
    KE.show({
        id : 'content',
		resizeMode : 1,
        cssPath : './index.css',
        items : [
        'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
        'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
        'insertunorderedlist', 'emoticons', 'image', 'link']
    });
  </script>
<script>

layui.cache.page = '';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: '../res/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "2.0.0"
  ,base: '../res/mods/'
}).extend({
  fly: 'index'
}).use('fly');
</script>
</body>
</html>